// 导入
import { formatDate } from './common.esm.js';

let divNow = document.getElementById('divNow');
divNow.innerHTML = formatDate(new Date());

// json: 数据格式，js内置了对json支持
/* 
  alt + shift + a 多行注释
  json的格式:{
    字段名称: 字段值
    字段2:值2，
    ...
  }
  值可以是任意类型
*/
let user = {
  username: '',
  Password: 'admin',
  salay: 10000,
  dept: {
    name: '开发部',
    ids: [1, 2, 55],
  },
};

let divUser = document.getElementById('divUser');

divUser.innerHTML = `${user.username}`;

// 通过json数据动态生成页面
let divMenus = document.getElementById('divMenus');

let menus = [
  { title: '黑暗骑士的网站', link: 'https://huhuiyu.top' },
  { title: '哔哩哔哩', link: 'https://bilibili.com' },
  { title: '腾讯QQ', link: 'https://im.qq.com' },
];

for (let i = 0; i < menus.length; i++) {
  let data = menus[i];
  let alink = document.createElement('a');
  alink.append(data.title);
  alink.setAttribute('href', data.link);

  divMenus.append(alink);
}
